<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :before-close="handleDialogClose"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    class="subcribe-common-dialog small-common-dialog-size"
  >
    <DialogTitle :title="title" font-size="16px" style="margin-bottom:20px;"/>
    <div class="flex-center">
      <div class="input-label">{{ title }}：</div>
      <div class="input-box">
        <el-date-picker
          v-model="planPaymentDate"
          clearable
          value-format="timestamp"
          size="small"
          type="date"
          format="yyyy/MM/dd"
          placeholder="请选择"/>
      </div>
    </div>
    <div class="dialog-footer">
      <el-button class="ok" type="primary" @click="handleConfirm">确定</el-button>
      <el-button class="cancel-btn-style" type="info" @click="handleDialogClose">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import DialogTitle from '@/components/Title';

export default {
  components: {
    DialogTitle
  },
  props: {
    title: {
      type: String,
      default: '计划支付日期'
    },
    currDate: {
      type: String | Number,
      default: null
    }
  },
  data() {
    return {
      dialogVisible: false,
      planPaymentDate: null
    };
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.planPaymentDate = this.currDate;
      }
    }
  },
  methods: {
    handleDialogClose() {
      this.dialogVisible = false;
      this.planPaymentDate = null;
    },
    handleConfirm() {
      this.$emit('confirm', this.planPaymentDate);
      this.handleDialogClose();
    }
  }
};
</script>

<style lang="scss" scoped>
.input-label {
  margin-right: 12px;
  line-height: 32px;
  color: #666;
  align-self: self-start;
  flex-shrink: 0;
  .require-icon {
    color: red;
  }
}
.input-box {
  width: 220px;
  ::v-deep .el-input__inner {
    height: 32px;
    line-height: 32px;
    width: 220px;
    font-size: 14px;
  }
}
.dialog-footer {
  display: flex;
  justify-content: center;
  margin-top: 25px;
  .ok {
    width: 120px;
    font-size: 16px;
    padding: 8px 20px;
  }
  .cancel-btn-style {
    font-size: 14px;
    padding: 8px 20px;
    margin-left: 16px !important;
  }
}
</style>
